package neusoft.example.com.yuejian06.Activity;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.squareup.picasso.Picasso;

import java.util.List;

import neusoft.example.com.yuejian06.Bean.Competition;
import neusoft.example.com.yuejian06.Fragment.CompetitionFragment;
import neusoft.example.com.yuejian06.Model.CompetitionModel;
import neusoft.example.com.yuejian06.PublicActivity;
import neusoft.example.com.yuejian06.R;
import neusoft.example.com.yuejian06.RetrofitListener;

public class CompetitionDetailActivity extends AppCompatActivity{

    private Intent intent;
    private ImageView competition_return;
    private ImageView competition_pic;
    private String competition_id;
    private TextView competition_name;
    private TextView competition_starttime;
    private TextView competition_endtime;
    private TextView competition_detail;
    private Button competition_button;

    private RetrofitListener<Competition> competitionlistener;
    private RecyclerView recyclerView;
    private CompetitionModel competitionModel;
    private LinearLayoutManager layoutManager;

    private PublicActivity publicActivity;
    private SharedPreferences sp;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_competition_detail);

        ActionBar actionBar = getSupportActionBar();
        if(actionBar != null){
            actionBar.setDisplayHomeAsUpEnabled(true);
        }
        initView();

        //sp = getSharedPreferences("competition_id", MODE_PRIVATE);
        competition_id = getIntent().getStringExtra("competition_id");

        layoutManager = new LinearLayoutManager(CompetitionDetailActivity.this);
        layoutManager.setOrientation(LinearLayoutManager.VERTICAL);

        competitionlistener=new RetrofitListener<Competition>() {
            PublicActivity publicActivity=new PublicActivity();
            @Override
            public void onResponse(Competition l) {
                Picasso.with(CompetitionDetailActivity.this)
                        .load(publicActivity.getIp()+"static/picture/"+l.getCompetition_pic())
                        .into(competition_pic);

                competition_detail.setText(l.getCompetition_detail());
                competition_starttime.setText(l.getCompetition_starttime());
                competition_endtime.setText(l.getCompetition_endtime());
                competition_name.setText(l.getCompetition_name());
            }

            @Override
            public void onFail(String msg) {
                Toast.makeText(CompetitionDetailActivity.this, msg, Toast.LENGTH_SHORT).show();
            }
        };

        competitionModel = new CompetitionModel();
        competitionModel .getCompetition(competition_id, competitionlistener);

        competition_return.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                intent=new Intent(CompetitionDetailActivity.this, CompetitionFragment.class);
                startActivity(intent);
            }
        });

    }


private void initView(){
        competition_name=(TextView)findViewById(R.id.competition_name);
        competition_return=(ImageView)findViewById(R.id.competition_return);
        competition_pic=(ImageView)findViewById(R.id.competition_pic);
        competition_starttime=(TextView)findViewById(R.id.competition_starttime);
        competition_endtime=(TextView)findViewById(R.id.competition_endtime);
        competition_detail=(TextView)findViewById(R.id.competition_detail);
}



}
